package cn.tedu;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Demo03 {
    public static void main(String[] args) throws Exception{

        Connection conn = DriverManager.getConnection(
                "jdbc:mysql://localhost:3307/empdb?characterEncoding=utf8&serverTimezone=Asia/Shanghai","root","3307");

        Statement s = conn.createStatement();

        //增
        //s.executeUpdate("insert into emp(name) value ('tom')");

        //改
        //s.executeUpdate("update emp set name = 'jerry' where name = 'tom'");

        //删
        //s.executeUpdate("delete from emp where name = 'jerry'");

        //查
        ResultSet resultSet = s.executeQuery("select name,sal from emp");
        while (resultSet.next()){
//            String name = resultSet.getString("name");
//            double sal = resultSet.getDouble("sal");
            String name = resultSet.getString(1);
            double sal = resultSet.getDouble(2);
            System.out.println(name + "," + sal);
        }

        System.out.println("Finished");
        conn.close();
    }
}
